/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.db.DbMailItem;
/*     */ import com.zimbra.cs.db.DbResults;
/*     */ import com.zimbra.cs.db.DbUtil;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.service.formatter.HeadersOnlyInputStream;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestMailItem
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*     */   private static final int TEST_CONTACT_ID = 9999;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  44 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void testListItemIds() throws Exception
/*     */   {
/*  49 */     Account account = TestUtil.getAccount("user1");
/*  50 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
/*     */     
/*     */ 
/*  53 */     String sql = "SELECT folder_id, type, count(*) AS item_count FROM " + DbMailItem.getMailItemTableName(mbox) + " WHERE mailbox_id = " + mbox.getId() + " GROUP BY folder_id, type";
/*     */     
/*     */ 
/*     */ 
/*  57 */     DbResults results = DbUtil.executeQuery(sql, new Object[0]);
/*  58 */     assertTrue("No results returned", results.size() > 0);
/*     */     
/*     */ 
/*  61 */     while (results.next()) {
/*  62 */       int folderId = results.getInt("folder_id");
/*  63 */       MailItem.Type type = MailItem.Type.of((byte)results.getInt("type"));
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*  68 */       int count = results.getInt(3);
/*  69 */       ZimbraLog.test.debug("Confirming that folder " + folderId + " has " + count + " items of type " + type);
/*     */       
/*  71 */       Folder folder = mbox.getFolderById(null, folderId);
/*  72 */       assertNotNull("Folder not found", folder);
/*     */       
/*  74 */       List<Integer> ids = mbox.listItemIds(null, type, folderId);
/*  75 */       assertEquals("Item count does not match", count, ids.size());
/*     */     }
/*     */   }
/*     */   
/*     */   public void testHeadersOnlyInputStream()
/*     */     throws Exception
/*     */   {
/*  82 */     String s = "test";
/*  83 */     ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes());
/*  84 */     HeadersOnlyInputStream headerStream = new HeadersOnlyInputStream(in);
/*  85 */     String read = new String(ByteUtil.getContent(headerStream, s.length()));
/*  86 */     assertEquals(s, read);
/*     */     
/*     */ 
/*  89 */     s = "\r\n\r\ntest";
/*  90 */     in = new ByteArrayInputStream(s.getBytes());
/*  91 */     headerStream = new HeadersOnlyInputStream(in);
/*  92 */     read = new String(ByteUtil.getContent(headerStream, s.length()));
/*  93 */     assertEquals(0, read.length());
/*     */     
/*     */ 
/*  96 */     s = "te\r\n\r\nst";
/*  97 */     in = new ByteArrayInputStream(s.getBytes());
/*  98 */     headerStream = new HeadersOnlyInputStream(in);
/*  99 */     read = new String(ByteUtil.getContent(headerStream, s.length()));
/* 100 */     assertEquals("te", read);
/*     */     
/*     */ 
/* 103 */     s = "test\r\n\r\n";
/* 104 */     in = new ByteArrayInputStream(s.getBytes());
/* 105 */     headerStream = new HeadersOnlyInputStream(in);
/* 106 */     read = new String(ByteUtil.getContent(headerStream, s.length()));
/* 107 */     assertEquals("test", read);
/*     */     
/*     */ 
/* 110 */     s = "te\r\n\rst";
/* 111 */     in = new ByteArrayInputStream(s.getBytes());
/* 112 */     headerStream = new HeadersOnlyInputStream(in);
/* 113 */     read = new String(ByteUtil.getContent(headerStream, s.length()));
/* 114 */     assertEquals(s, read);
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 119 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception {
/* 123 */     Mailbox mbox = TestUtil.getMailbox("user1");
/* 124 */     mbox.delete(null, 9999, MailItem.Type.CONTACT);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestMailItem.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */